package mapViewer.screens;



//import midlets.microGoogleTalk.MicroGoogleTalk;
//import midlets.microGoogleTalk.AccountRecord;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;

import context.*;

import mapViewer.AccountRecord;
import mapViewer.MapViewer;

// ******************************************************************
// *** CLASS: AccountScreen
// ******************************************************************
public class AccountDetailsScreen extends Form implements Debug.Constants
{ //private static final boolean DEBUG=true; // Overriding Debug.Constants.DEBUG
  public final static int MAX_USERID=32;
  public final static int MAX_PASSWORD=32;
  public final static int MAX_HOST=32;
  public final static int MAX_PORT=32;
  public final static int MAX_SERVICE_NAME=32;
  public final static int MAX_RESOURCE=32;
  private static final Command okCommand=new Command("OK",Command.OK,0);
  private static final Command cancelCommand=new Command("Cancel",Command.CANCEL,0);

  private Display display;
  private Displayable prev;
  private TextField userID;
  private TextField password;
  private TextField host;
  private TextField port;
  private TextField serviceName;
  private TextField resource;


  public AccountDetailsScreen(final MapViewer midlet,final AccountRecord account)
  { super("Account@"+account.getServiceName());
    this.display=Display.getDisplay(midlet);
    if(DEBUG) Debug.println("New AccountScreen");
    this.addCommand(okCommand);
    this.addCommand(cancelCommand);
    
    userID=new TextField("user ident",account.getUserID(),MAX_USERID,TextField.ANY);
    password=new TextField("password",account.getPassword(),MAX_PASSWORD,TextField.PASSWORD);
    host=new TextField("host",account.getHost(),MAX_HOST,TextField.ANY);
    port=new TextField("port",""+account.getPort(),MAX_PORT,TextField.DECIMAL);
    serviceName=new TextField("serviceName",account.getServiceName(),MAX_SERVICE_NAME,TextField.ANY);
    resource=new TextField("resource",account.getResource(),MAX_RESOURCE,TextField.ANY);
    append(userID);
    append(password);
    append(host);
    append(port);
    append(serviceName);
    append(resource);
    
    this.setCommandListener(new CommandListener()
    { public void commandAction(Command c,Displayable s)
      {	if(c==cancelCommand) display.setCurrent(prev);
    	if(c==okCommand)
    	{ // update
          account.setUserID(userID.getString());
          account.setPassword(password.getString());
          account.setHost(host.getString());
//          account.setPort(port.getString());
          account.setServiceName(serviceName.getString());
          account.setResource(resource.getString());
          if(prev instanceof AccountScreen) ((AccountScreen)prev).update();
          display.setCurrent(prev);
    	}
    	  
      }
    });
  }
  
  public void show()
  { prev=display.getCurrent();
    display.setCurrent(this);
  }
}
